import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
// 重写push/replace方法
// 解决vue-router在3.0版本以上重复点菜单报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const originalReplace = Router.prototype.replace
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}


//发现音乐
const Home = () => import('@/views/home/Home')
const PerRecommend = () => import("@/views/home/childComps/per-recommend/PerRecommend");
const Customization = () => import("@/views/home/childComps/customization/Customization");
const SongListPage = () => import("@/views/home/childComps/song-list/SongListPage");
const Top = () => import("@/views/home/childComps/top/Top");
const Singer = () => import("@/views/home/childComps/singer/Singer");
//最新音乐页
const NewMusic = () => import("@/views/home/childComps/new-music/NewMusic");
const NewSong = () => import("@/views/home/childComps/new-music/childcomps/NewSongs");
const NewAlbum = () => import("@/views/home/childComps/new-music/childcomps/NewAlbums");
//歌单详情页
const SongListDetail = () => import('@/components/content/songlistdetail/SongListDetail')
const SongListDetailContent = () => import('@/components/content/songlistdetail/childComps/SonglistDetailContent')
const SonglistDetailComment = () => import('@/components/content/songlistdetail/childComps/SonglistDetailComment')
const SonglistDetailCollector = () => import('@/components/content/songlistdetail/childComps/SonglistDetailCollector')
//歌手详情页
const SingerDetail = () => import('@/components/content/singerdetail/SingerDetail')
const SingerAlbum = () => import('@/components/content/singerdetail/childcomps/SingerAlbum')
const SingerMV = () => import('@/components/content/singerdetail/childcomps/SingerMV')
const SingerDesc = () => import('@/components/content/singerdetail/childcomps/SingerDesc')
const SingerSimilar = () => import('@/components/content/singerdetail/childcomps/SingerSimilar')
//专辑页
const Album = () => import("@/components/content/album/Album");
const AlbumContent = () => import("@/components/content/album/childcomps/AlbumContent");
const AlbumComment = () => import("@/components/content/album/childcomps/AlbumComment");
const AlbumDesc = () => import("@/components/content/album/childcomps/AlbumDesc");
//搜索页
const SearchPage = () => import("@/components/content/search/SearchPage");
const SearchSong = () => import ("@/components/content/search/childcomps/SearchSong");
const SearchSinger = () => import("@/components/content/search/childcomps/SearchSinger");
const SearchAlbum = () => import("@/components/content/search/childcomps/SearchAlbum");
const SearchVideo = () => import("@/components/content/search/childcomps/SearchVideo");
const SearchSongList = () => import("@/components/content/search/childcomps/SearchSongList");
//视频页
const Father = () => import('@/views/video/Father')
const Video = () => import('@/views/video/Video')
const MV = () => import('@/views/video/Mv')
//每日推荐页
const DailyRecommend = () => import("@/views/dailyrecommend/DailyRecommend");
//我的收藏页
const MyCollect = () => import("@/views/mycollect/MyCollect");
const MyCollectAlbum = () => import("@/views/mycollect/childcomps/MyCollectAlbum");
const MyCollectSinger= () => import("@/views/mycollect/childcomps/MyCollectSinger");
const MyCollectVideo = () => import("@/views/mycollect/childcomps/MyCollectVideo");


//mv详情页
const MvDetail = () => import("@/components/content/mvdetail/MvDetail");
//视频详情页
const VideoDetail = () => import("@/components/content/videodetail/VideoDetail");

export default new Router({
  mode:'history',
  routes: [
    // 默认路由
    {
      path:'',
      redirect:'/home'
    },
    //发现音乐
    {
      path:'/home',
      component:Home,
      children:[
        {
          path: '',
          redirect:'/home/perRecommend'
        },
        //个性推荐页
        {
          path:'/home/perRecommend',
          component:PerRecommend,
          children:[
            //歌单详情页（初次写复杂的路由，经验不足，不应把这个公共的路由写在这里）
            //可以跟个性推荐页平级
            {
              path:'/songlist/detail/id=:id',
              component:SongListDetail,
              children: [
                {
                  path: '',
                  redirect:'/songlist/detail/id=:id/songlist'
                },
                {
                  path:'/songlist/detail/id=:id/songlist',
                  component:SongListDetailContent,
                  // meta: {
                  //   keepAlive:true,
                  // },
                },
                {
                  path:'/songlist/detail/id=:id/comment',
                  component:SonglistDetailComment,
                },
                {
                  path:'/songlist/detail/id=:id/collector',
                  component:SonglistDetailCollector,
                }
              ],
            },
          ]
        },
        // 专属订制页
        {
          path:'/home/customization',
          component:Customization,
        },
        // 歌单页
        {
          path:'/home/songList',
          component:SongListPage,
          meta: {
            keepAlive:true,
          },
        },
        // 排行榜页
        {
          path:'/home/top',
          component:Top,
          meta: {
            keepAlive:true,
          },
        },
        // 歌手页
        {
          path:'/home/singer',
          component:Singer,
          meta: {
            keepAlive:true,
          },
        },
        // 最新音乐页
        {
          path:'/home/newMusic',
          component:NewMusic,
          redirect: '/home/newMusic/newSong',
          children: [
            //新歌速递页
            {
              path: '/home/newMusic/newSong',
              component:NewSong,
            },
            //新碟上架页
            {
              path: '/home/newMusic/newAlbum',
              component:NewAlbum,
            }
          ],
        },


        //歌手详情页
        {
          path:'/singer/:id',
          component:SingerDetail,
          redirect: '/album/id=:id',
          children: [
            //专辑页(注意一下album这里取得不好，但是又不好修改，后面的专辑页才应该取这个名字)
            {
              path:'/album/id=:id',
              component:SingerAlbum,
            },
            //MV页
            {
              path:'/MV/id=:id',
              component:SingerMV,
            },
            //歌手详情
            {
              path:'/describe/id=:id',
              component:SingerDesc,
            },
            //相似歌手
            {
              path:'/similar/id=:id',
              component:SingerSimilar,
            },
          ],
        },
        //专辑页
        {
          path: '/album',
          component:Album,
          redirect: '/album/song/id=:id',
          children: [
            //专辑歌单
            {
              path: '/album/song/id=:id',
              component:AlbumContent,
            },
            //专辑评论区
            {
              path: '/album/comment/id=:id',
              component:AlbumComment,
            },
            //专辑描述
            {
              path: '/album/describe/id=:id',
              component:AlbumDesc,
            },
          ],
        },
        //搜索页
        {
          path: '/search/:data',
          component:SearchPage,
          redirect: '/search/searchsong/:data',
          children: [
            //单曲搜索页
            {
              path: '/search/searchsong/:data',
              component: SearchSong,
            },
            // 歌手搜索页
            {
              path: '/search/searchsinger/:data',
              component: SearchSinger,
            },
            // 专辑搜索页
            {
              path: '/search/searchalbum/:data',
              component: SearchAlbum,
            },
            // 视频搜索页
            {
              path: '/search/searchvideo/:data',
              component: SearchVideo,
            },
            // 歌单搜索页
            {
              path: '/search/searchsonglist/:data',
              component: SearchSongList,
            },
          ],
        },
      ]
    },
    //视频
    {
      path:'/videoPage',
      component:Father,
      redirect:'/videoPage/mv',
      children:[
        {
          path:'/videoPage/mv',
          component:MV
        },
        {
          path:'/videoPage/video',
          component:Video
        },
      ],
    },
    //每日推荐
    {
      path: '/dailyRecommend/id=:id',
      component:DailyRecommend,
    },
    //我的收藏
    {
      path: '/myCollect/id=:id',
      component:MyCollect,
      redirect:'/myCollect/id=:id/album',
      children:[
        {
          path:'/myCollect/id=:id/album',
          component:MyCollectAlbum
        },
        {
          path:'/myCollect/id=:id/singer',
          component:MyCollectSinger,
        },
        {
          path:'/myCollect/id=:id/video',
          component:MyCollectVideo
        },
      ]
    },

    //mv详情页
    {
      path: '/mvdetail/id=:id',
      component:MvDetail,
    },
    //视频详情页
    {
      path: '/videodetail/id=:id',
      component:VideoDetail,
    },
  ],
})
